/*
 * SPDX-FileCopyrightText: 2022-2023 liulinsong <liulinsong@kylinos.cn>
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 *
 */

#include "physicalkeyboardwatcherstrategy.h"

namespace fcitx {

PhysicalKeyboardWatcherStrategy::PhysicalKeyboardWatcherStrategy(
    SubjectAvailabilityChangedCallback availabilityChangedCallback)
    : Strategy("PhysicalKeyboardWatcherStrategy", "inputmethod_change_signal",
               "get_inputmethod_mode", std::move(availabilityChangedCallback)) {
}

PhysicalKeyboardWatcherStrategy::~PhysicalKeyboardWatcherStrategy() = default;

bool PhysicalKeyboardWatcherStrategy::isSubjectDefaultAvailable() const {
    return false;
}

bool PhysicalKeyboardWatcherStrategy::isSubjectAvailableFromMethodMessage(
    dbus::Message &message) const {
    int isPhysicalKeyboardAvailable =
        static_cast<int>(isSubjectDefaultAvailable());

    auto reply = message.call(0);
    reply >> isPhysicalKeyboardAvailable;

    return static_cast<bool>(isPhysicalKeyboardAvailable);
}

} // namespace fcitx
